// pages/Main/mainIndex/mainIndex.js
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
var common = require('../../../utils/common.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: "",
    num: 1,
    scrollHeight: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let c = common.Getorgid();
    var scrollHeight = scrollHeight;
    wx.getSystemInfo({
      success: function (res) {
        scrollHeight = res.windowHeight
      }
    });
    this.setData({
      orgid: c.orgid,
      userid: c.userid,
      scrollHeight: scrollHeight,
    });
    this.QueryAndKnowledge();

  },
  bindDownLoad: function () {
    if (this.data.lenpage > this.data.num) {
      var di = this.data.num;
      var di = di + 1;
      this.setData({
        num: di
      });
      this.QueryAndKnowledge();
    } else {
      common.showToast("到底了", "loading");
    }
  },
  testpra: function (event) {
    wx.navigateTo({
      url: "../testpra/testpra?title=收藏练习&&iscorrect=2&&subscribing=2&&remarktype=5&&examtype=1&&testid=" + event.currentTarget.dataset.testid
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  QueryAndKnowledge: function () {
    common.showToast("加载中", "loading");
    let params = { "page": this.data.num, "num": 15, "orgid": this.data.orgid, "userid": this.data.userid, searchField: "peopleid,iscollect", "searchValue": this.data.userid + "," + "1" }
    businessLogic.QueryAndKnowledge(params, (res) => {
      //console.log(params)
      console.log(res);
      for (let a = 0; a < res.infos.length; a++) {
        // console.log(res[a].title);
        var x = "";
        var kemucolor1 = ""
        switch (res.infos[a].subject_dictionary_title) {
          case "语文":
            x = "yuwen"
            break;
          case "数学":
            x = "shuxue"
            break;
          case "英语":
            x = "english"
            break;
          case "物理":
            x = "wuli"
            break;
          case "化学":
            x = "huaxue"
            break;
          case "政治":
            x = "zhengzhi"
            break;

          default:
            x = "zhengzhi";
        }
        res.infos[a].color = [];
        res.infos[a].color.push(x);
      }
      /*  var bbb = this.data.bookCollectList;
       for (var a = 0; a < res.infos.length; a++) {
         bbb.push(res.infos[a]);
       }  */
      this.setData({
        bookCollectList: res.infos,
        //lenpage: res.page.pages
      });
    });
  },
  bindKeyInput: function (e) {
    this.setData({
      title: e.detail.value
    })
  },
  search2: function (event) {
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, searchField: "peopleid,testid|试题系统模型|title,iscollect", "searchValue": "" + this.data.userid + "," + this.data.title + ",1" }
    businessLogic.QueryAndKnowledge(params, (res) => {
      //console.log(params)
      //console.log(res);

      for (let a = 0; a < res.length; a++) {
        // console.log(res[a].title);
        var x = "";
        var kemucolor1 = ""
        switch (res[a].subject_dictionary_title) {
          case "语文":
            x = "yuwen"
            break;
          case "数学":
            x = "shuxue"
            break;
          case "英语":
            x = "english"
            break;
          case "物理":
            x = "wuli"
            break;
          case "化学":
            x = "huaxue"
            break;
          case "政治":
            x = "zhengzhi"
            break;

          default:
            x = "zhengzhi";
        }
        res[a].color = [];
        res[a].color.push(x);
      }

      this.setData({
        bookCollectList: res
      });
    });
  }
})